package com.zyh.scs.admin.controller;

import com.zyh.scs.admin.api.dto.UserDTO;
import com.zyh.scs.admin.service.SysUserService;
import com.zyh.scs.common.core.util.R;
import com.zyh.scs.common.log.annotation.SysLog;
import com.zyh.scs.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author scs
 * @date 2022/3/30
 * <p>
 * 客户端注册功能 register.user = false
 */
@Inner(value = false)
@RestController
@RequestMapping("/register")
@AllArgsConstructor
@Tag(description = "客户端注册功能", name = "客户端注册功能")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegisterController {

    private final SysUserService userService;

    /**
     * 注册用户
     *
     * @param userDto 用户信息
     * @return success/false
     */
    @SysLog("注册用户")
    @PostMapping("/user")
    @ConditionalOnProperty(name = "register.user", matchIfMissing = true)
    public R<Boolean> registerUser(@RequestBody UserDTO userDto) {
        return userService.registerUser(userDto);
    }

    /**
     * 重置用户密码
     *
     * @param userDto 用户信息
     * @return success/false
     */
    @SysLog("重置用户密码")
    @PostMapping("/password")
    @Operation(summary = "重置用户密码",description = "重置用户密码")
    public R<Boolean> resetUserPassword(@RequestBody UserDTO userDto) {
        return userService.resetUserPassword(userDto);
    }

}
